Skip to content

Conversation

hasanmo
Copy link
Member

@hasanmo hasanmo commented Oct 23, 2026

Adds persistent recipe ratings and image uploads to the frontend integration.

  • Users can create, update and remove their rating on other users’ public recipes.
  • Clicking the summary stars opens the rating dialog.
  • Supports image selection, cropping, upload and removal, with JPG/PNG/WebP validation and a 5 MB limit.
  • Stores images in a persistent Docker volume.
  • Adds the application logo as the favicon.
  • Enables file polling for reliable frontend updates on Windows Docker setups.

Validation: repository checks passed with 224 tests, API/database tests and all 9 browser tests.

Notes: image URLs are publicly readable, and unreferenced files are retained. Advanced search and sorting remain planned for D3.

@hasanmo hasanmo requested a review from a team as a code owner October 23, 2026 13:12
Copy link
Member

@oliveror oliveror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was assisted by AI.

SHOULD FIX BEFORE MERGE

  1. Every mutation blanks the page (apps/web/src/features/recipes/useRecipeQuery.ts:12)
    Each save/unsave/rating bumps revision, which is part of the request key. loading flips to true and the page swaps its content for a spinner.

    • Detail page: the content unmounts, so the success toast is lost and the servings scaling resets.
    • Explore/Cookbook: one Save click replaces the whole grid with "Loading recipes…" and loses scroll position.
    • If the refetch fails after a successful mutation, the user sees a full-page error.
      Suggested fix: keep the previous data while refetching and expose a separate refreshing flag.
  2. State updates after unmount (apps/web/src/features/recipe-detail/RecipeDetailPage.tsx:231)
    performAction calls invalidateRecipes(), which unmounts the component. The later setFeedback and setBusy(false) run on a dead instance, so the success toast never shows.

    • openRating() doesn't clear feedback, so reopening the rating dialog shows a stale error alert.
    • Errors appear twice, once in the dialog and once in the toast.
  3. Double fetch on first load (useRecipeQuery.ts:13)
    sessionStatus is in the request key. A hard refresh sends a request while the session is "restoring", aborts it, then sends another.

    • On the edit page, a late session change can remount RecipeEditor and wipe what the user has typed.
      Suggested fix: don't fetch while sessionStatus === 'restoring', and drop it from the key.
  4. Edit route owner check (apps/web/src/features/recipes/RecipeCreatePage.tsx:531)

    • If query.data loads before currentUser, the user briefly sees "Recipe unavailable" for their own recipe.
    • A malformed /recipes/abc/edit URL gets the misleading "You can only edit your own recipes" message.
    • The 'new' route still subscribes to revision, so it re-renders on every save elsewhere.

IMAGE UPLOAD: SECURITY AND RESOURCES

  1. Uploads are never cleaned up (apps/api/src/features/recipes/imageStorage.ts:97)
    Files are written to disk but not tied to a recipe. Replacing or removing an image, cancelling the form, or deleting a recipe all leave the file behind. Registration is open and /uploads has no per-user quota or rate limit, so a script could fill the disk or the recipe_images volume.

  2. Uploaded images are public (imageStorage.ts:49)
    GET /uploads/<uuid> has no authentication or visibility check. An image for a private recipe stays readable by anyone with the URL, including after the recipe is made private. The response has no Cache-Control, even though the UUID filenames never change.

  3. Unguarded upload response (apps/web/src/features/recipes/recipeImages.ts:27)

    • response.json() on a 200 response isn't guarded. A proxy returning HTML would show the raw SyntaxError in the crop dialog. A missing imageUrl would pass undefined to onChange.
    • The 5 MB check runs on the original file, but cropImage re-encodes at full resolution. A large crop can exceed 5 MB and only fail at upload time.

CLEANUP

  1. Dead mock code (apps/web/src/features/explore/mockExploreQuery.ts, mockCookbookQuery.ts)
    They are now only imported by tests, so the tests cover logic production no longer runs. The diff redeclares local ExploreSort/CookbookSort unions to keep them compiling, and these will drift from the real ones.

  2. Validation module has a filesystem dependency (apps/api/src/features/recipes/recipeValidation.ts:3)
    The pure zod module imports imageStorage.ts (node:fs, auth, cookies) just for a regex. filePattern and uploadedImagePattern are duplicated by hand. If they diverge, a recipe could accept an imageUrl the file route always 404s, or the reverse.

MINOR

  • RecipeQueryStatus.tsx:12 hardcodes "Loading recipes…" for the detail and edit pages as well. Combined with 1, screen readers re-announce it after every mutation.

@hasanmo hasanmo requested a review from a team October 26, 2026 08:20
@hasanmo
Copy link
Member Author

hasanmo commented Oct 26, 2026

This review was assisted by AI.

SHOULD FIX BEFORE MERGE

  1. Every mutation blanks the page (apps/web/src/features/recipes/useRecipeQuery.ts:12)
    Each save/unsave/rating bumps revision, which is part of the request key. loading flips to true and the page swaps its content for a spinner.

    • Detail page: the content unmounts, so the success toast is lost and the servings scaling resets.
    • Explore/Cookbook: one Save click replaces the whole grid with "Loading recipes…" and loses scroll position.
    • If the refetch fails after a successful mutation, the user sees a full-page error.
      Suggested fix: keep the previous data while refetching and expose a separate refreshing flag.
  2. State updates after unmount (apps/web/src/features/recipe-detail/RecipeDetailPage.tsx:231)
    performAction calls invalidateRecipes(), which unmounts the component. The later setFeedback and setBusy(false) run on a dead instance, so the success toast never shows.

    • openRating() doesn't clear feedback, so reopening the rating dialog shows a stale error alert.
    • Errors appear twice, once in the dialog and once in the toast.
  3. Double fetch on first load (useRecipeQuery.ts:13)
    sessionStatus is in the request key. A hard refresh sends a request while the session is "restoring", aborts it, then sends another.

    • On the edit page, a late session change can remount RecipeEditor and wipe what the user has typed.
      Suggested fix: don't fetch while sessionStatus === 'restoring', and drop it from the key.
  4. Edit route owner check (apps/web/src/features/recipes/RecipeCreatePage.tsx:531)

    • If query.data loads before currentUser, the user briefly sees "Recipe unavailable" for their own recipe.
    • A malformed /recipes/abc/edit URL gets the misleading "You can only edit your own recipes" message.
    • The 'new' route still subscribes to revision, so it re-renders on every save elsewhere.

IMAGE UPLOAD: SECURITY AND RESOURCES

  1. Uploads are never cleaned up (apps/api/src/features/recipes/imageStorage.ts:97)
    Files are written to disk but not tied to a recipe. Replacing or removing an image, cancelling the form, or deleting a recipe all leave the file behind. Registration is open and /uploads has no per-user quota or rate limit, so a script could fill the disk or the recipe_images volume.

  2. Uploaded images are public (imageStorage.ts:49)
    GET /uploads/<uuid> has no authentication or visibility check. An image for a private recipe stays readable by anyone with the URL, including after the recipe is made private. The response has no Cache-Control, even though the UUID filenames never change.

  3. Unguarded upload response (apps/web/src/features/recipes/recipeImages.ts:27)

    • response.json() on a 200 response isn't guarded. A proxy returning HTML would show the raw SyntaxError in the crop dialog. A missing imageUrl would pass undefined to onChange.
    • The 5 MB check runs on the original file, but cropImage re-encodes at full resolution. A large crop can exceed 5 MB and only fail at upload time.

CLEANUP

  1. Dead mock code (apps/web/src/features/explore/mockExploreQuery.ts, mockCookbookQuery.ts)
    They are now only imported by tests, so the tests cover logic production no longer runs. The diff redeclares local ExploreSort/CookbookSort unions to keep them compiling, and these will drift from the real ones.
  2. Validation module has a filesystem dependency (apps/api/src/features/recipes/recipeValidation.ts:3)
    The pure zod module imports imageStorage.ts (node:fs, auth, cookies) just for a regex. filePattern and uploadedImagePattern are duplicated by hand. If they diverge, a recipe could accept an imageUrl the file route always 404s, or the reverse.

MINOR

  • RecipeQueryStatus.tsx:12 hardcodes "Loading recipes…" for the detail and edit pages as well. Combined with 1, screen readers re-announce it after every mutation.

Addresses the integration review feedback:

  • Preserves page content, servings and form state during background refreshes.
  • Fixes session-related duplicate requests, edit-route messages and stale rating errors.
  • Adds image ownership metadata, visibility checks, upload quotas and orphan cleanup.
  • Validates upload responses and resizes cropped images before uploading.
  • Removes unused mock queries and centralizes image-path validation.
  • Adds a Docker test guide.

Includes a migration that imports existing recipe image references. Unreferenced images are cleaned up after 24 hours.

Validation: repository checks passed with 206 tests, API/database tests and all 9 browser tests.

@hasanmo hasanmo requested review from oliveror and olestan October 26, 2026 14:27
Copy link
Member

@oliveror oliveror left a comment •

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was assisted by AI.

Thanks, the previous review points are addressed (query keeps data on refresh, unmount guard and stale errors, session wait, edit route messages, image ownership/visibility, upload response validation, dead mocks removed, image path validation centralised on the API side). Requesting changes for the items below, mostly around the new image storage.

SHOULD FIX BEFORE MERGE

  1. New image logic is not tested in CI (.github/workflows/ci.yml)
    • CI runs types:check, db:check, check and test:e2e. It does not run npm run test:api or npm run test:db.
    • Those two scripts hold all the tests for ownership, privacy, quotas, concurrency, cleanup and the legacy-image migration. imageStorage.test.ts now only tests against a mocked store.
    • The browser test skips itself without DATABASE_URL, and I could not find one in ci.yml.
    • As it stands, CI can pass without running any of the new image logic.

Suggested fix: add test:api and test:db to the workflow, or confirm the runner provides DATABASE_URL.

  1. One global lock serialises all recipe writes (imageRepository.ts, imageStore.ts, recipeRepository.ts)
    • validateImageReference takes the exclusive advisory lock ${schema}:uploaded_images on every recipe create/update, even without an image. delete takes it too.
    • upload holds the lock while it runs readdir and stat on up to 1000 files and writes the file.
    • cleanup holds it while it runs one or more queries per file, plus the unlinks.
    • During the hourly cleanup every recipe write in the app waits, and recipe writes also queue behind each other.

Suggested fix: use pg_advisory_xact_lock_shared for recipe writes and keep the exclusive lock for upload/cleanup only, or take the lock only when an image URL is involved.

  1. Upload limits do not hold against account spam (imageStore.ts DEFAULT_LIMITS)
    • Registration is open, so the per-user limits (20/hour, 100 MiB) can be bypassed with new accounts.
    • The global limits (1000 files, 1 GiB) then become the failure point: everyone gets 507 until cleanup frees space, which takes 24 hours.
    • The global cap also counts referenced images, so the site can never hold more than 1000 recipe images.
    • The limits are hard-coded defaults, not configurable.

Suggested fix: throttle registration or uploads per IP, make the limits configurable, and count only unreferenced files towards the abuse cap. If this is out of scope for now, please document the limitation.

@oliveror
Copy link
Member

In addition to the above feedback, I see that quite a few test files are failing? I don't believe those are related to these commits, they also fail on dev, but it might be worth following up in a follow-up issue.

@oliveror oliveror self-requested a review October 27, 2026 10:19
Copy link
Member

@oliveror oliveror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Throttle registration and lock serialises is something we have agreed to potentially look into at a later time, so we can focus on functionality at this stage.

@hasanmo hasanmo merged commit d8c9c0b into dev Oct 27, 2026
2 checks passed
@hasanmo hasanmo mentioned this pull request Oct 28, 2026
@oliveror oliveror deleted the hasan/feat/recipe-frontend-integration branch October 30, 2026 10:45
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants